Giter Site home page Giter Site logo

zaxebo1 / pgtsql Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bigsql/pgtsql

0.0 1.0 0.0 259 KB

Transact-SQL Compatibility for PostgreSQL. Not just for Sybase & SQL Server anymore.

Home Page: https://bigsql.org/docs/pgtsql

Makefile 3.20% PLpgSQL 12.16% Yacc 78.46% C 5.37% TSQL 0.19% Perl 0.61%

pgtsql's Introduction

pgTSQL

Overview

Transact-SQL is now available in PostgreSQL (in addition to Sybase & SQL Server).

pgTSQL is an extension that provides:

  • PostgreSQL procedural language that implements the Transact-SQL language.
  • Built-in functions, such as getdate() and isnull()
  • System catalog views, such as SYS.TABLES and SYS.OBJECTS

T-SQL (Transact-SQL) is the procedural programming language built into Sybase & SQL Server. It's functionally the equivalent of PostgreSQL's PL/pgSQL. It looks a bit different because it has unique conventions like:

  • Semicolons are not required at the end of each line of code
  • Variable names always are prefixed with @ signs
  • IF statements do not need to be closed by END IF's
  • Temporary tables are automagic if the table name has a # prefix

History of project

This project was originally part of an OpenSCG PostgreSQL distribution call tPostgres that fizzled about seven years ago. Five years ago Jim Mlodgenski ported it as a standalone extension for PG9.5 BigSQL. Early in 2019 Denis Lussier upgraded it to build with PG10. In late 2019 Korry Douglas upgraded it for PG11 support in v3.0 (including support for stored procedures instead of just stored functions).

Installation

Use the BigSQL command line to install PostgreSQL 11 and then the pgtsql extension

./apg install pg11
./apg start pg11
./apg install pgtsql-pg11

Example

Now lets use psql to create a table and a small sample TSQL function as follows.

CREATE TABLE rdbms_supports_tsql (
  organization  varchar(10) primary key
);
INSERT INTO rdbms_supports_tsql VALUES ('SYBASE');
INSERT INTO rdbms_supports_tsql VALUES ('SQL-SERVER');
INSERT INTO rdbms_supports_tsql VALUES ('POSTGRES') ;


CREATE OR REPLACE FUNCTION query_tsql_rdbms() RETURNS void AS $$
  DECLARE @val int = 0. 
BEGIN
  SELECT count(*) INTO @val FROM rdbms_supports_tsql;
  IF @val = 2
    PRINT 'Proprietary market featuring vendor lock-in'
  ELSE
    PRINT 'Open Source innovation means choices'
END
$$ LANGUAGE pltsql;

Building from Source

The REL_3 branch is for building against PG 11.

For installation there must be PostgreSQL dev environment installed and pg_config in the PATH. Then just run:

$ make
$ make install

To run regression tests:

$ make installcheck

Notes:

  • Location to pg_config can be set via PG_CONFIG variable:

    $ make PG_CONFIG=/path/to/pg_config $ make install PG_CONFIG=/path/to/pg_config $ make installcheck PG_CONFIG=/path/to/pg_config

pgtsql's People

Contributors

luss avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.