NeonN
Neon2y ago
9 replies
dead-brown

I need to create table with columns named "from" and "to".

Hi guys.

I need to create table with columns named "from" and "to".
But I get
NeonDbError: syntax error at or near "from"
and when I put in double quotes then I get
NeonDbError: syntax error at or near ")"

Please tell me how I can solve it.

here is my code

import { neon } from "@neondatabase/serverless";
import { drizzle } from "drizzle-orm/neon-http";
import { sql } from "drizzle-orm";
import { DATABASE_URL } from "../env";

const sql = neon(DATABASE_URL);
export const db = drizzle(sql);

export async function createTable(tableName: string): Promise<void> {
  const query = sql`
        CREATE TABLE IF NOT EXISTS ${sql.identifier(tableName)} (
            hash TEXT PRIMARY KEY,
            block_hash TEXT,
            block_number INTEGER,
            block_time TIMESTAMP,
            type TEXT,
            nonce INTEGER,
            gas_limit INTEGER,
            gas_price TEXT,
            gas_used INTEGER,
            max_fee_per_gas INTEGER,
            max_priority_fee_per_gas INTEGER,
            priority_fee_per_gas INTEGER,
            success BOOLEAN,
            l1_block_number INTEGER,
            l1_fee TEXT,
            l1_fee_scalar INTEGER,
            l1_gas_price TEXT,
            l1_gas_used INTEGER,
            l1_timestamp TIMESTAMP,
            l1_tx_origin TEXT,
            data TEXT,
            from TEXT,  
            to TEXT, 
            value TEXT,
            block_date TIMESTAMP,
            accessList TEXT,
            index INTEGER,
            access_list TEXT,
            max_fee_per_blob_gas INTEGER,
        );
    `;
  await db.execute(query);

  console.log(`Table ${tableName} has been created.`);
}
Was this page helpful?